package jiChengHeDuoTai.duoTai3.xiangXiaHeXiangShangZhuanXing;

public class Test {
    public static void main1(String[] args) {
        //像上转型发生动态绑定
        Animal animal=new Dog("旺财",10);
        animal.eat();
    }

    public static void func(Animal animal){
        //第二种向上转型办法
        animal.eat();
    }
    public static void main2(String[] args) {
        Dog dog=new Dog("旺财",10);
        func(dog);
        System.out.println("=======");
        Bird bird=new Bird("小鸟",2);
        func(bird);
    }

    public static int add(int a,int b,int c){
        return a+b+c;
    }

    public static int add(int a,int b){
        return a+b;
    }

    public static void main3(String[] args) {
        //方法重载
        add(1,2);
        add(1,2,3);
    }

    //向下转型
    public static void main(String[] args) {
        Animal animal=new Bird("小鸟",2);

        Bird bird=(Bird)animal;

        bird.fly();

        System.out.println("=======");

        Animal animal2=new Dog("单身狗",10);
        //aniaml2 这个引用是否引用了Bird这个对象,引用失败
        if(animal2 instanceof Bird){
            Bird bird2=(Bird) animal2;
            bird2.fly();
        }else{
            System.out.println("animal instanceof Bird not!!!");
        }
    }
}
